package com.hjm.project.terminal.activate.controller;

import java.util.List;

import com.hjm.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.terminal.activate.domain.FeignActivate;
import com.hjm.project.terminal.activate.service.IFeignActivateService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * activateController
 * 
 * @author maker-platform
 * @date 2021-03-10
 */
@Controller
@RequestMapping("/activate/activate")
public class FeignActivateController extends BaseController
{
    private String prefix = "terminal/activate";

    @Resource
    private IFeignActivateService feignActivateService;

    @RequiresPermissions("activate:activate:view")
    @GetMapping()
    public String activate()
    {
        return prefix + "/activate";
    }

    /**
     * 查询activate列表
     */
    @RequiresPermissions("activate:activate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FeignActivate feignActivate)
    {
        startPage();
        List<FeignActivate> list = feignActivateService.selectFeignActivateList(feignActivate);
        return getDataTable(list);
    }

    /**
     * 导出activate列表
     */
    @RequiresPermissions("activate:activate:export")
    @Log(title = "activate", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FeignActivate feignActivate)
    {
        List<FeignActivate> list = feignActivateService.selectFeignActivateList(feignActivate);
        for (FeignActivate activate : list) {
            String numName = activate.getNumName();
            if (StringUtils.isNotEmpty(numName)) {
                String[] split = numName.split(",");
                activate.setTopAgentNum(split[0]);
                activate.setTopAgentName(split[1]);
            }
        }
        ExcelUtil<FeignActivate> util = new ExcelUtil<FeignActivate>(FeignActivate.class);
        return util.exportExcel(list, "activate");
    }

    /**
     * 新增activate
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存activate
     */
    @RequiresPermissions("activate:activate:add")
    @Log(title = "activate", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FeignActivate feignActivate)
    {
        return toAjax(feignActivateService.insertFeignActivate(feignActivate));
    }

    /**
     * 修改activate
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        FeignActivate feignActivate = feignActivateService.selectFeignActivateById(id);
        mmap.put("feignActivate", feignActivate);
        return prefix + "/edit";
    }

    /**
     * 修改保存activate
     */
    @RequiresPermissions("activate:activate:edit")
    @Log(title = "activate", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FeignActivate feignActivate)
    {
        return toAjax(feignActivateService.updateFeignActivate(feignActivate));
    }

    /**
     * 删除activate
     */
    @RequiresPermissions("activate:activate:remove")
    @Log(title = "activate", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(feignActivateService.deleteFeignActivateByIds(ids));
    }
}
